import express from 'express';
import { CaseController } from '../controllers/caseController';
import { authenticate, authorize } from '../middleware/auth';

const router = express.Router();
const caseController = new CaseController();

// === 用户端路由 ===

// 获取案例列表
router.get('/web/cases', caseController.getCases.bind(caseController));

// 获取单个案例详情
router.get('/web/cases/slug/:slug', caseController.getCaseBySlug.bind(caseController));

// 获取推荐案例
router.get('/web/cases/recommend', caseController.getRecommendCases.bind(caseController));

// 获取置顶案例
router.get('/web/cases/top', caseController.getTopCases.bind(caseController));

// 获取案例分类
router.get('/web/case-categories', caseController.getCaseCategories.bind(caseController));

// === 管理端路由 ===

// 获取案例列表 (管理端)
router.get('/admin/cases', authenticate, authorize(['admin','editor']), caseController.getAdminCases.bind(caseController));

// 获取案例统计
router.get('/admin/cases/stats', authenticate, authorize(['admin','editor']), caseController.getCaseStats.bind(caseController));

// 导出案例
router.get('/admin/cases/export', authenticate, authorize(['admin','editor']), caseController.exportCases.bind(caseController));

// 获取单个案例详情 (管理端)
router.get('/admin/cases/:id', authenticate, authorize(['admin','editor']), caseController.getCaseById.bind(caseController));

// 创建案例
router.post('/admin/cases', authenticate, authorize(['admin','editor']), caseController.createCase.bind(caseController));

// 更新案例
router.put('/admin/cases/:id', authenticate, authorize(['admin','editor']), caseController.updateCase.bind(caseController));

// 删除案例
router.delete('/admin/cases/:id', authenticate, authorize(['admin','editor']), caseController.deleteCase.bind(caseController));

// === 案例分类管理 ===

// 获取案例分类列表 (管理端)
router.get('/admin/case-categories', authenticate, authorize(['admin','editor']), caseController.getAdminCaseCategories.bind(caseController));

// 获取单个案例分类 (管理端)
router.get('/admin/case-categories/:id', authenticate, authorize(['admin','editor']), caseController.getCaseCategoryById.bind(caseController));

// 创建案例分类
router.post('/admin/case-categories', authenticate, authorize(['admin','editor']), caseController.createCaseCategory.bind(caseController));

// 更新案例分类
router.put('/admin/case-categories/:id', authenticate, authorize(['admin','editor']), caseController.updateCaseCategory.bind(caseController));

// 删除案例分类
router.delete('/admin/case-categories/:id', authenticate, authorize(['admin','editor']), caseController.deleteCaseCategory.bind(caseController));

export default router; 